Skip to content

fix(libkernel): support socket fcntl duplication - #7437

Open
lucaslima430 wants to merge 1 commit into
boykopovar:mainfrom
lucaslima430:fix/libkernel-socket-fcntl-duplication
Open

lucaslima430 wants to merge 1 commit into
boykopovar:mainfrom
lucaslima430:fix/libkernel-socket-fcntl-duplication

Conversation

@lucaslima430

@lucaslima430 lucaslima430 commented Oct 18, 2026 •

Copy link
Copy Markdown

What

  • Implement F_DUPFD, F_DUPFD_CLOEXEC, F_DUP2FD, and F_DUP2FD_CLOEXEC for guest socket descriptors with the lowest-free-descriptor and close-on-exec semantics used by FreeBSD 11.4.
  • Forward every typed sceKernelFcntl variadic argument to the guest-socket path, including pointer arguments for unsupported lock commands, and preserve descriptor metadata when an exact-target duplicate replaces another descriptor type.
  • Cover minimum bounds, invalid arguments, exact-target replacement, close-on-exec behavior, pointer-command error translation, and cross-type descriptor replacement.
  • Update the libkernel debt entry to retain only the remaining socket ownership and console-verification gaps.
  • Rebase resolution preserves the host-socket documentation from merged fix(libkernel): handle fcntl and FIONREAD on a host socket descriptor #7403 together with the guest-socket duplication behavior in this PR.
  • The refreshed overlap scan reports fix(libkernel): fail a malformed ioctl request with ENOTTY #7956 at neighboring test/debt lines. Direct inspection shows its malformed ioctl handling does not implement guest-socket fcntl duplication; no functional dependency was identified. test: organize library tests and label CTest suites #6044 reorganizes tests; feat: macOS on Apple Silicon host support (Rosetta 2 and MoltenVK) #7332 changes Apple-only socket paths. The scan could not compare several PRs conflicting with main, so those results are incomplete rather than proof of no overlap.

Tested

  • Rebased onto main e80325a4c7; head b6b1255830.
  • Windows 11 10.0.26200, WinLibs GCC 15.2.0, Release: cmake --build build --target libkernel guest_socket_descriptor_flags_tests guest_kernel_fcntl_tests guest_dup_tests guest_socket_descriptors_tests guest_udp_tests guest_tcp_tests --parallel 4 passed after initializing the new upstream mimalloc submodule with git submodule update --init --recursive.
  • Windows: ctest --test-dir build -R '^(guest_socket_descriptor_flags|guest_kernel_fcntl|guest_dup|guest_socket_descriptors|guest_udp|guest_tcp)$' --output-on-failure passed 6/6.
  • WSL Ubuntu 26.04, GCC 15.2.0, Release: the same focused build targets passed; the same six CTest cases passed 6/6. guest_kernel_fcntl includes host-socket checks from fix(libkernel): handle fcntl and FIONREAD on a host socket descriptor #7403.
  • The builds and tests ran on the conflict-resolved tree. Subsequent rebases brought unrelated upstream changes; independent Git comparisons verified final libkernel, libc and focused test sources remained identical to that tested tree.
  • python tools/check_conventions.py --base origin/main: 0 errors, 1 debt-length warning on the existing long fcntl entry.
  • git diff --check origin/main...HEAD: passed. Conflict-marker, UTF-8 BOM and machine-specific absolute-path checks passed.
  • python tools/pr_overlap.py --branch fix/libkernel-socket-fcntl-duplication --repo boykopovar/AnyPS5: completed; findings and comparison limitations described above.
  • No console validation or full-suite run was performed in this rebase session.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 4630 docs/dev/debt/libkernel.md
PR 5021 core/libs/prx/libkernel/File/src/Open.cpp
core/libs/prx/libkernel/Socket/src/Udp.cpp
docs/dev/debt/libkernel.md
PR 6044 core/libs/tests/GuestKernelFcntl.cpp
core/libs/tests/GuestSocketDescriptorFlags.cpp
PR 6149 docs/dev/debt/libkernel.md
PR 6469 docs/dev/debt/libkernel.md
PR 6519 docs/dev/debt/libkernel.md
PR 6658 docs/dev/debt/libkernel.md
PR 6740 docs/dev/debt/libkernel.md
PR 6893 docs/dev/debt/libkernel.md
PR 6936 core/libs/prx/libkernel/File/src/Open.cpp
docs/dev/debt/libkernel.md
PR 6977 core/libs/prx/libkernel/Socket/src/Udp.cpp
core/libs/tests/GuestKernelFcntl.cpp
docs/dev/debt/libkernel.md
PR 7049 docs/dev/debt/libkernel.md
PR 7105 docs/dev/debt/libkernel.md
PR 7149 docs/dev/debt/libkernel.md
PR 7201 core/libs/prx/libkernel/File/src/Open.cpp
core/libs/prx/libkernel/Socket/src/Udp.cpp
PR 7464 docs/dev/debt/libkernel.md
PR 7509 docs/dev/debt/libkernel.md

@jotitadev jotitadev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linux run, since the description lists only Windows.

Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release, BUILD_TESTING=ON, full build.
Head d35db7be1 merged onto main 9caecfd2d (clean merge).

  • guest_kernel_fcntl and guest_socket_descriptor_flags pass, as do the other fcntl/socket/dup tests (ctest -R "fcntl|socket|dup|udp|tcp", 19 tests).
  • The two test files only, on main:
    • guest_socket_descriptor_flags fails at F_DUPFD must honor the minimum and clear FD_CLOEXEC (errno 22);
    • guest_kernel_fcntl aborts at sceKernelFcntl(socket, GetDescriptorFlags) == 1 right after sceKernelFcntl(socket, SetDescriptorFlags, 1) (I numbered the Require calls to find it): on main only F_SETFL forwards its argument for a socket, which is the Open.cpp change.
  • Non-GPU suite (ctest -E "^agc|gpu|vulkan|video_out"): 712/712, same as main.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

@lucaslima430

Copy link
Copy Markdown
Author

Rebased this PR on current main (a62c724c3; head 5c624a139). Coordination check:

Proposal: Depends on: none; either PR may merge first, then any later PR rebases its nearby Udp.cpp/debt context. Please flag a contrary dependency.

@milescoviello

Copy link
Copy Markdown
Contributor

@lucaslima430 agreed, sorry for the slow reply. #7403 only changes the path for host sockets that aren't guest sockets, and this PR changes F_DUP* on guest sockets. There's no dependency either way. The shared debt entry is a text conflict for whichever lands second, and I'll take it if #7403 is second.

AI-assisted: yes (Claude Code)

@lucaslima430
lucaslima430 force-pushed the fix/libkernel-socket-fcntl-duplication branch from 5c624a1 to 335ce43 Compare October 18, 2026 21:19
@lucaslima430

Copy link
Copy Markdown
Author

Rebased onto current main (0d1c299a9; head 335ce43d8). During the variadic forwarding review, I found that sceKernelFcntl consumed pointer arguments but did not pass them to the guest-socket fcntl path, which then attempted to consume a missing argument. The new head forwards pointer arguments too and covers an unsupported lock command returning EINVAL through the expected translated path.

Windows targeted build and the six socket/fcntl/dup tests pass (6/6); python3 tools/check_conventions.py --base origin/main passes; the current overlap scan reports #7403 only at the shared debt line, with no functional dependency as already agreed above. Linux was not rerun on this head; the earlier independent Linux result remains attached to its reviewed commit.

AI-assisted: yes (Codex); implementation and test results were independently inspected in this session.

@lucaslima430
lucaslima430 force-pushed the fix/libkernel-socket-fcntl-duplication branch from 335ce43 to 45e35c5 Compare October 18, 2026 21:47
@lucaslima430

Copy link
Copy Markdown
Author

Follow-up validation after the final rebase (0bc3003f8 -> 45e35c552):

  • Windows Release build completed for libkernel and the six focused test targets; CTest passed 6/6.
  • WSL Ubuntu 26.04, Linux 6.18.54.1, GCC 15.2.0: the same focused build completed; CTest passed 6/6.
  • python3 tools/check_conventions.py --base origin/main passed.
  • git diff --check origin/main...HEAD passed.
  • The earlier note that Linux had not been rerun is superseded by this validation.
  • A later overlap refresh timed out without producing a result; the last completed scan and manual review remain documented in the PR body.

No machine-specific absolute paths were used in these reproduction instructions.

@lucaslima430

Copy link
Copy Markdown
Author

Reviewed the newly reported overlap with #7509. It changes equeue pending-event bounds and a separate libkernel debt entry; it does not touch socket descriptor duplication behavior and creates no functional dependency. A context-only debt-file rebase may be needed for whichever PR lands second.

AI-assisted: yes (Codex); the patch was inspected directly.

@lucaslima430
lucaslima430 force-pushed the fix/libkernel-socket-fcntl-duplication branch from 45e35c5 to 3910171 Compare October 18, 2026 22:03
@lucaslima430

Copy link
Copy Markdown
Author

Final rebase update: current main is 07377573f and this PR head is 39101716f. The intervening main changes were AGC fixes plus libc copysign in an unrelated file. After rebasing, the Windows and WSL Ubuntu focused builds both completed and the six socket/fcntl/dup tests passed 6/6 on each platform. Conventions and git diff --check also passed.

AI-assisted: yes (Codex); all results above were rerun on the stated head.

@DavidAmsellem

Copy link
Copy Markdown
Contributor

First AMD-on-Linux (RADV) run of this PR. Merged onto main 0fbfd91e5 (clean merge), built in full and compared with the same main, on the same machine.

AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 (Ubuntu 24.04 base), kernel 7.0.0-38, GCC 13.3, Release.

Full suite (ANYPS5_REQUIRE_VULKAN=1 ctest -j8): 1637/1639 with this PR, against 1637/1639 on main. The failures are the same two on both, so this PR adds none: agc_driver_image_table_vouched_lookups (#7766, fixed by #7916) and agc_driver_guest_memory_lifetime (#7784). The PR adds no new ctest entry, and no test is skipped or removed compared with main.

GPUs tested: n/a (libkernel change; suite run on the machine above)

AI-assisted: yes

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 19, 2026
@lucaslima430
lucaslima430 force-pushed the fix/libkernel-socket-fcntl-duplication branch from 3910171 to b6b1255 Compare October 19, 2026 20:02
@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Oct 19, 2026
@adriadam10
adriadam10 force-pushed the fix/libkernel-socket-fcntl-duplication branch from b6b1255 to bbcce17 Compare October 20, 2026 11:42
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 20, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants